'use strict';

var md5 = require('md5-node');
const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const { ctx } = this;
    // ctx.body = 'hi, egg';
    await ctx.render('indec', {
      arr: ['香蕉', '苹果', '鸭梨']
    });
  }
  async getdata() {
    this.ctx.body = 'halou'
  }
  async md() {
    let pass = this.ctx.request.body.pass
    this.ctx.body = {
      md: md5(this.app.config.jwt.secret + pass + this.app.config.jwt.secret),
      mds: this.app.config.jwt.secret + pass + this.app.config.jwt.secret
    }
  }
  async mds() {
    let pass = this.ctx.request.body.pass
    let usr = this.ctx.request.header["user-agent"]
    this.ctx.body = {
      usr: usr
    }
  }

  //发送邮箱
  async node() {
    const email = this.ctx.request.body.email;  // 接收者的邮箱
    const has_send = await this.service.sendemail.sendMail(email);

    if (has_send) {
      this.ctx.body = {
        message: '发送成功',
      };
      return;
    }
    this.ctx.body = {
      message: '发送失败',
    };
    // this.ctx.body=await this.ctx.service.node.node();
  }
}

module.exports = HomeController;
